package com.ruoyi.womp.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.womp.domain.WompElement;
import com.ruoyi.womp.service.IWompElementService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 要素列表Controller
 * 
 * @author mzz
 * @date 2022-04-11
 */
@Controller
@RequestMapping("/womp/element")
public class WompElementController extends BaseController
{
    private String prefix = "womp/element";

    @Autowired
    private IWompElementService wompElementService;

    @RequiresPermissions("womp:element:view")
    @GetMapping()
    public String element()
    {
        return prefix + "/element";
    }

    /**
     * 查询要素列表列表
     */
    @RequiresPermissions("womp:element:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WompElement wompElement)
    {
        startPage();
        List<WompElement> list = wompElementService.selectWompElementList(wompElement);
        return getDataTable(list);
    }

    /**
     * 导出要素列表列表
     */
    @RequiresPermissions("womp:element:export")
    @Log(title = "要素列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WompElement wompElement)
    {
        List<WompElement> list = wompElementService.selectWompElementList(wompElement);
        ExcelUtil<WompElement> util = new ExcelUtil<WompElement>(WompElement.class);
        return util.exportExcel(list, "要素列表数据");
    }

    /**
     * 新增要素列表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存要素列表
     */
    @RequiresPermissions("womp:element:add")
    @Log(title = "要素列表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WompElement wompElement)
    {
        return toAjax(wompElementService.insertWompElement(wompElement));
    }

    /**
     * 修改要素列表
     */
    @RequiresPermissions("womp:element:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        WompElement wompElement = wompElementService.selectWompElementById(id);
        mmap.put("wompElement", wompElement);
        return prefix + "/edit";
    }

    /**
     * 修改保存要素列表
     */
    @RequiresPermissions("womp:element:edit")
    @Log(title = "要素列表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WompElement wompElement)
    {
        return toAjax(wompElementService.updateWompElement(wompElement));
    }

    /**
     * 删除要素列表
     */
    @RequiresPermissions("womp:element:remove")
    @Log(title = "要素列表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wompElementService.deleteWompElementByIds(ids));
    }
}
